package com.collect.cameroon.zhiScene.zhiPhoneReview.zhiFollow;

import android.content.Context;

import com.collect.cameroon.zhiBase.BasePresenter;
import com.collect.cameroon.zhiBase.BaseSubscriber;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRPhoneReviewListEntity;
import com.collect.cameroon.zhiBean.zhiSend.ZHISPhoneReviewFollowEntity;
import com.collect.cameroon.zhiBean.zhiSend.ZHISPhoneReviewMarkedEntity;
import com.collect.cameroon.zhiNetApi.ZHIHttpApiProvider;
import com.collect.cameroon.zhiNetApi.ZHIHttpResponse;
import com.collect.cameroon.zhiUtils.RxSchedulers;

import javax.inject.Inject;

public class ZHIPhoneReviewFollowPresenter extends BasePresenter<ZHIPhoneReviewFollowContract.View> implements ZHIPhoneReviewFollowContract.Presenter {

    @Inject
    public ZHIPhoneReviewFollowPresenter() {

    }

    @Override
    public void getPhoneReviewList(Context context, ZHISPhoneReviewFollowEntity zhisPhoneReviewFollowEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ZHIRPhoneReviewListEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRPhoneReviewListEntity>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRPhoneReviewListEntity zhirPhoneReviewListEntity = (ZHIRPhoneReviewListEntity) object;
                            mView.onGetPhoneReviewList(zhirPhoneReviewListEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().phoneReviewOrderList(zhisPhoneReviewFollowEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void markPhoneReview(Context context, ZHISPhoneReviewMarkedEntity zhisPhoneReviewMarkedEntity) {
        BaseSubscriber<ZHIHttpResponse> subscriber = new
                BaseSubscriber<ZHIHttpResponse>(context, this, true) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            mView.onMarkPhoneReview();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().markPhoneReview(zhisPhoneReviewMarkedEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}
